package com.easyaop.api;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;

public class EasyAopBinderClassLoader extends ClassLoader {


    protected Class<?> findClass(URL url,String className) {
        //读取 jar 包中的 class文件
        try (BufferedInputStream bis = new BufferedInputStream(url.openStream()); ByteArrayOutputStream ois = new ByteArrayOutputStream()) {
            int len;
            byte[] buf = new byte[1024];
            while ((len = bis.read(buf)) != -1) {
                ois.write(buf,0,len);
            }
            byte[] data = ois.toByteArray();
            return defineClass(className, data, 0, data.length);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
